; Music of Ghost Hunters (1987) (Codemasters)
; Ripped by Megachur the 05/02/2009

; Need System Vectors

	write "GHOSTHUN.BIN"

music_date_rip	equ &0529
music_adr	equ &9202
first_theme	equ 0
last_theme	equ 0	; 0 -> 0

	read "music_header_v1_0.asm"

;
.init_music
;
	call #bca7
	ld a,#01
	ld hl,l922d
	call #bcbf
	ld hl,l938d
	ld b,#81
	ld c,#00
	ld de,l923b
	call #bcd7
	ld hl,(l9367)
	ld (l9369),hl
	ld hl,(l9377)
	ld (l9379),hl
	ld hl,(l9387)
	ld (l9389),hl
	ret
.l922d
	db #82,#06,#ff,#01,#06,#01,#01
	ld hl,l938d
	call #bcdd
	ret
;
.play_music
;
.l923b
	push af
	ld a,(l936b)
	dec a
	dec a
	ld (l936b),a
	ld a,#00
	call z,l9265
	ld a,(l937b)
	dec a
	dec a
	ld (l937b),a
	ld a,#01
	call z,l9265
	ld a,(l938b)
	dec a
	dec a
	ld (l938b),a
	ld a,#02
	call z,l9265
	pop af
	ret
.l9265
	push bc
	push de
	push hl
	push ix
	push iy
	ld b,#00
	add a
	add a
	add a
	add a
	ld c,a
	ld iy,l935d
	add iy,bc
.l9279
	ld l,(iy+#0c)
	ld h,(iy+#0d)
	push hl
	pop ix
.l9282
	ld a,(ix+#00)
	cp #ff
	jr z,l92fc
	cp #fe
	jr z,l930b
	cp #fd
	jp z,l931f
	cp #fc
	jr z,l9315
	cp #fb
	jr z,l92f2
	cp #fa
	jp z,l9329
	ld a,(ix+#00)
	ld hl,l9396
	sla a
	ld b,#00
	ld c,a
	add hl,bc
	ld a,(hl)
	ld (iy+#03),a
	inc hl
	ld a,(hl)
	ld (iy+#04),a
	ld a,(ix+#01)
	ld (iy+#07),a
	ld (iy+#0e),a
	ld l,(iy+#0c)
	ld h,(iy+#0d)
	inc hl
	inc hl
	ld (iy+#0c),l
	ld (iy+#0d),h
	push iy
	pop hl
	call #bcaa
	pop iy
	pop ix
	pop hl
	pop de
	pop bc
	ret
.l92d9
	ld a,#00
	ld (iy+#09),a
.l92de
	ld l,(iy+#0c)
	ld h,(iy+#0d)
	inc hl
	inc hl
	inc ix
	inc ix
.l92ea
	ld (iy+#0c),l
	ld (iy+#0d),h
	jr l9282
.l92f2
	ld a,(ix+#01)
	and #1f
	ld (iy+#05),a
	jr l92de
.l92fc
	ld a,(iy+#0a)
	ld (iy+#0c),a
	ld a,(iy+#0b)
	ld (iy+#0d),a
	jp l9279
.l930b
	ld a,(ix+#01)
	and #0f
	ld (iy+#01),a
	jr l92de
.l9315
	ld a,(ix+#01)
	and #0f
	ld (iy+#02),a
	jr l92de
.l931f
	ld a,(ix+#01)
	and #0f
	ld (iy+#06),a
	jr l92de
.l9329
	ld a,(iy+#09)
	cp #01
	jr z,l933d
	ld a,#01
	ld (iy+#09),a
	ld a,(ix+#01)
	and #0f
	ld (iy+#0f),a
.l933d
	ld a,(iy+#0f)
	cp #00
	jr z,l92d9
	dec a
	ld (iy+#0f),a
	ld a,(ix+#01)
	and #f0
	rrca
	rrca
	rrca
	ld b,#00
	ld c,a
	push ix
	pop hl
	sbc hl,bc
	push hl
	pop ix
	jr l92ea
.l935d
	db #01,#00,#00,#00,#00,#00,#00,#00
.l936b equ $ + 6
.l9369 equ $ + 4
.l9367 equ $ + 2
	db #00,#00
	dw l9410,l9410
	db #02,#00
	db #02,#00,#00,#00,#00,#00,#00,#00
	db #00,#00
.l9379 equ $ + 2
.l9377
	dw l9471,l9471
.l937b
	db #02,#00,#04,#00,#00,#00,#00,#00
	db #00,#00,#00,#00
.l9389 equ $ + 2
.l9387
	dw l94d2,l94d2
.l938d equ $ + 2
.l938b
	db #02,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00
.l9396
	dw #03bc,#0386,#0353,#0324
	dw #02f6,#02cc,#02a4,#027e
	dw #025a,#0238,#0218,#01fa
	dw #01de,#01c3,#01aa,#0192
	dw #017b,#0166,#0152,#013f
	dw #012d,#011c,#010c,#00fd
	dw #00ef,#00e1,#00d5,#00c9
	dw #00be,#00b3,#00a9,#009f
	dw #0096,#008e,#0086,#007f
	dw #0077,#0071,#006a,#0064
	dw #005f,#0059,#0054,#0050
	dw #004b,#0047,#0043,#003f
	dw #003c,#0038,#0035,#0032
	dw #002f,#002d,#002a,#0028
	dw #0026,#0024,#0022,#0020
	dw #0000
.l9410
	db #fe,#00,#fc,#01,#fb,#00,#fd,#07
	db #0c,#50,#0e,#20,#0f,#40,#0c,#40
	db #fd,#07,#11,#50,#13,#20,#14,#40
	db #11,#40,#13,#50,#14,#20,#fd,#07
	db #13,#20,#11,#20,#fd,#06,#0f,#20
	db #0e,#20,#fd,#05,#0c,#40,#fd,#06
	db #0f,#40,#13,#40,#fd,#07,#18,#40
	db #14,#60,#14,#20,#13,#20,#11,#20
	db #fd,#07,#0f,#20,#fd,#06,#0e,#20
	db #fd,#05,#0c,#40,#fd,#06,#0f,#40
	db #fd,#07,#13,#40,#fd,#07,#18,#40
	db #fd,#07,#1b,#80,#fd,#06,#1a,#70
	db #ff
.l9471
	db #fe,#00,#fc,#01,#fb,#00,#fd,#07
	db #00,#50,#02,#20,#03,#40,#00,#40
	db #fd,#07,#05,#50,#07,#20,#08,#40
	db #05,#40,#07,#50,#08,#20,#fd,#07
	db #07,#20,#05,#20,#fd,#06,#03,#20
	db #02,#20,#fd,#05,#00,#40,#fd,#06
	db #03,#40,#07,#40,#fd,#07,#0c,#40
	db #08,#60,#08,#20,#07,#20,#05,#20
	db #fd,#07,#03,#20,#fd,#06,#02,#20
	db #fd,#05,#00,#40,#fd,#06,#03,#40
	db #fd,#07,#07,#40,#fd,#07,#0c,#40
	db #fd,#07,#0f,#80,#fd,#06,#0e,#70
	db #ff
.l94d2
	db #fe,#00,#fd,#00,#00,#02,#ff
	ld hl,#0040
	ld de,#0508
	call l94e3
	ret
.l94e3
	push hl
	push de
	call l9545
	pop de
	pop hl
.l94ea
	ld b,#08
.l94ec
	rlc (hl)
	push bc
	call c,l950f
	call nc,l9519
	push hl
	ld h,#01
	call l9523
	pop hl
	pop bc
	djnz l94ec
	inc hl
	dec de
	ld a,d
	or e
	jr nz,l94ea
	call #bca7
	ei
	ld a,#07
	call #bcb3
	ret
.l950f
	push af
	ld a,#09
	ld c,#0f
	call l9529
	pop af
	ret
.l9519
	push af
	ld a,#09
	ld c,#00
	call l9529
	pop af
	ret
.l9523
	ld h,#01
.l9525
	dec h
	jr nz,l9525
	ret
.l9529
	push af
	ld a,#c0
	ld b,#f6
	out (c),a
	ld b,#f4
	pop af
	out (c),a
	ld b,#f6
	ld a,#80
	out (c),a
	ld b,#f4
	out (c),c
	ld b,#f6
	xor a
	out (c),a
	ret
.l9545
	call #bca7
	di
	ld a,#03
	ld c,#00
	call l9529
	ld a,#07
	ld c,#3d
	call l9529
	ld a,#02
	ld c,#00
	call l9529
	ret
;
.game_name
	db "Ghost Hunters",0
.game_year
	db "1987",0
.game_publisher
	db "Codemasters",0
.music_author
	db "",0
.music_comment
	db "",0

	read "music_end_v1_0.asm"
